<?php

namespace ctrl;

use common\Ctrl;
use model\videos;
use model\common;
use libs\view;

class video extends ctrl
{
	static function init()
	{
		\model\visits::insertData(); //用户访问记录 写入记数
	}

	public static function index()
	{
		if (!isset($_GET['id']) & empty($_GET['id']) & empty(ROUTE['params']['id']))
			return  parent::_404();

		$info = videos::findData();
		if (!$info)
			return  parent::_404();

		$info['groupname'] = common::findAdminGroupData($info['gid']);
		$info['nickname'] = common::findAdminUserData($info['uid']);

		videos::hitsData(); //浏览+1

		view::assign('info', $info);
		view::Display("info_default");
	}

	public static function videolist()
	{
		if (empty($_GET['cid']) & empty(ROUTE['params']['cid']))
			return  parent::_404();

		$list = videos::listData(ROUTE['query']['cid']);

		view::assign('list', $list['data'] ?: null);

		view::assign('page', $list['page']);
		view::assign('cid', $list['cate']['id']);
		view::assign('catename', $list['cate']['name']);
		view::display($list['cate']['theme'] ?: "list_default");
	}
}
